using Shinkansen.Core;
using Shinkansen.Runtime;

namespace Shinkansen.Model
{
    public class QueryStringWithCompressionBuilder : IQueryStringBuilder
    {
        private readonly IQueryStringBuilder _builder;
        private readonly HttpCompressionMode _compressionMode;

        /// <summary>
        /// Initializes a new instance of the <see cref="QueryStringWithCompressionBuilder"/> class.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="compressionMode">The compression mode.</param>
        public QueryStringWithCompressionBuilder (IQueryStringBuilder builder, HttpCompressionMode compressionMode)
        {
            _builder = builder;
            _compressionMode = compressionMode;
        }

        /// <summary>
        /// Builds the specified query string.
        /// </summary>
        /// <param name="queryString">The query string.</param>
        public void ConstructQueryString (QueryString queryString)
        {
            _builder.ConstructQueryString (queryString);

            switch (_compressionMode)
            {
                case HttpCompressionMode.Deflate:
                    queryString[Tokens.Compression] = Tokens.DeflateCompression;
                    break;

                case HttpCompressionMode.GZip:
                    queryString[Tokens.Compression] = Tokens.GzipCompression;
                    break;
            }
        }
    }
}